ZSQL, Python Script, number of records
Hi, To check whether a record exists I'm using this: exist (ZSQL method): SELECT count(*) as I FROM ... WHERE ... ; Python Script: for x in exist(m_id=m_id): if x.i==0: print "no data" else: print "there are some data" This works... but it's strange to use "for" for it... is there a simpler method? Just an "if", wthout "for"? I tried to adapt the "exist" ZSQL to show a column from the table: exist2 (ZSQL method): SELECT count(*) as I, fname FROM ... WHERE ... ; It fails and it recommends to put "fname" into GROUP BY. So: exist3 (ZSQL method): SELECT count(*) as I, fname FROM ... WHERE ... GROUP BY fname; That works but IMHO it's a very ugly hack and it may breed trouble later on. Is there a more elegant way to get both values and number of values using a single ZSQL method? -- Milos Prudek
Milos Prudek writes:
To check whether a record exists I'm using this:
exist (ZSQL method): SELECT count(*) as I FROM ... WHERE ... ;
Python Script: for x in exist(m_id=m_id): if x.i==0: print "no data" else: print "there are some data"
x=exist(m_id=m_id)[0] ....
I tried to adapt the "exist" ZSQL to show a column from the table: exist2 (ZSQL method): SELECT count(*) as I, fname FROM ... WHERE ... ; You may want to read the SQL restrictions applying for accumulation functions like "count".
It fails and it recommends to put "fname" into GROUP BY. So: exist3 (ZSQL method): SELECT count(*) as I, fname FROM ... WHERE ... GROUP BY fname;
That works but IMHO it's a very ugly hack and it may breed trouble later on.
Is there a more elegant way to get both values and number of values using a single ZSQL method? I am not sure what you want to get.
Your "exist3" is definitely completely different from your "exist"! While "exist" always returns a single row, "exist3" may return any number of rows, especially 0 and many. Each row contains the value for "FNAME" and how often it occurs. If you want this result, the SQL query is completely natural. Otherwise, what do you want? Dieter
To check whether a record exists I'm using this:
exist (ZSQL method): SELECT count(*) as I FROM ... WHERE ... ;
Python Script: for x in exist(m_id=m_id): if x.i==0: print "no data" else: print "there are some data"
x=exist(m_id=m_id)[0]
What does that [0] mean? The first row of results from the "exist" ZSQL method? -- Milos Prudek
participants (2)
-
Dieter Maurer -
Milos Prudek