Oracle DEFAULT clause for create table. "Literal argument"? - sql

I was just reading the documentation for the CREATE TABLE statement and it says this in relation to the DEFAULT clause:
"The DEFAULT expression can include any SQL function as long as the
function does not return a literal argument, a column reference, or a
nested function invocation."
http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_7002.htm
What does it mean by the function cannot return a "literal argument". I thought returning literals was OK for DEFAULT?

Yes, it is OK to use literals with DEFAULT, for example DEFAULT 'YES' . What is telling you that text is that if you are using a function in DEFAULT, for example DEFAULT POWER(2,3) , that function POWER must not return a literal argument. You can use SQL built in functions in the clause DEFAULT , but not USER defined PLSQL functions

Related

SQL ''Field" = {variable}' Select by attribute arcpy

I am trying to run a select by attribute where I select all points where "Id" field matches the numeric variable point_id. point_id = 375.
I've tried a few quotation styles and using curly brackets to call my variable. I'm not the most familiar with SQL queries and get an error saying the positional argument follows the keyword string. I have also tried storing my SQL as a variable on it's own called a whereClause and get the same error.
First attempt code
arcpy.management.SelectLayerByAttribute(in_layer_or_view = deer,
selection_type = "NEW_SELECTION",
f'"Id"={point_id}')
Second attempt code
The is a Python issue, not related to ArcGIS or SQL.
You are trying to pass three arguments. For the first two arguments you're using keyword argument (explicitly specifying the argument name: in_layer_or_view = deer), but for the third one you're using positional argument (letting python assign the value to the appropriate argument based on the order of the arguments).
The execption you're getting is telling you that you can't mix the two types this way. Once you started using keyword arguments in the function call, all of the next argument must be passed with their explicit name too.
To fix this, you can use positional argument for all of the arguments (i.e. not specifing argument names at all), or alternatively keep specifing the names for all of the rest of the arguments.
In your case, this should work:
arcpy.management.SelectLayerByAttribute(in_layer_or_view=deer,
selection_type="NEW_SELECTION",
where_clause=f'"Id"={point_id}')
or alternatively:
arcpy.management.SelectLayerByAttribute(deer,
"NEW_SELECTION",
f'"Id"={point_id}')

How can I perform a regex/text search on a SUPER type?

What I'm doing now:
I have a table with one field that is a json value that is stored as a super type in my staging schema.
the field containing the json is called elements
In my clean table, I typecast this field to VARCHAR in order to search it and use string functions
I want to search for the string net within that json in order to determine the key/value that I want to use for my filter
I tried the following:
select
elements
, elements_raw
from clean.events
where 1=1
and lower(elements) like '%net%'
or strpos(elements,'net')
My output
When running the above query, I keep getting an empty set returned.
My issue
I tried running the above code and using the elements_raw value instead but I got an issue :ERROR: function strpos(super, "unknown") does not exist Hint: No function matches the given name and argument types. You may need to add explicit type casts.
I checked the redshift super page and it doesn't list any specifics on searching strings within super types
Desired result:
Perform string operations on super field
Cast super field to a string type
There are some super related idiosyncrasies that are being run into here:
You cannot change the type of a super field via :: or cast()
String functions like and strpos do not work on super types
To address both of these issues, you can use the function json_serialize to return your super as a string.

SQL Standard for function arguments

Is there a SQL standard for specifying function arguments as password type?
For example, if I write a SQL function, which can be called like:
my_func('host', 'port', 'user', 'pwd')
Is there a way for me to specify during function definition that the fourth argument is a password?
Edit: I am looking for either a data type or some attribute that can be used to indicate that the field is a password type field.

SQL: Agregate function for user defined type

I have user defined type:
create type indeks as integer
And question for my exam says: "Define aggregate function max for type indeks"
create function max(indeks)
returns indeks
source sysibm.max(integer);
Can you help me understand this? Because I know this is some elementary stuff.
create function max(indeks)
returns indeks
These two lines are OK, I'm creating function and return type is also indeks.
source sysibm.max(integer);
But this is what I don't understand. I have no idea what is this line for.
Thanks in advance.
The schema name SYSIBM is used for built-in data types and built-in functions. The function source from the SYSIBM.MAX catalog table is merged into the statement.
The built-in functions cannot simply
be applied to User Defined Types. If they are
required, then UDFs-based on the desired built-in functions must be generated. It means that you need to put this statement there
source sysibm.max(integer);

PostgreSQL create type PL/pgSQL and cstring

I wanna format some fields in the output of my PostgreSQL 9.1 database. I thought of creating a type, so I could do the formatting in the output function, and checking for inconsistencies in the input function. I decided to use the procedural language PL/pgSQL. But I'm getting some errors:
CREATE OR REPLACE FUNCTION "CPF_in"(cstring)
"PL/pgSQL functions cannot accept type cstring"
(But that's how it is in the manual.) I can put "character varying" instead of cstring, or even leave the () empty. But when I'm going to create the desired type:
CREATE TYPE Tcpf (
INPUT = CPF_in(character varying),
OUTPUT = CPF_out
);
I got an error:
ERROR: syntax error at or near ")"
LINE 2: INPUT = CPF_in(character varying),
and if I try
CREATE TYPE Tcpf (
INPUT = CPF_in(),
OUTPUT = CPF_out
);
I get
ERROR: syntax error at or near ")"
LINE 2: INPUT = CPF_in(),
How is this supposed to be done? The manual only say cstring...
The cstring pseudo-type is used for programming in a low-level language like C, not in PL/pgSQL. You have to use a low-level language like C if you're creating a new base type.
You must register two or more functions (using CREATE FUNCTION) before
defining the type. The support functions input_function and
output_function are required . . . .
Generally these functions have to be coded in C or another low-level
language.
A simpler way to control the output format is to use a view. If your formatting is complex, write a function, and call that function from a view. You can revoke permissions on the base table if you need to force every client to use your formatting. You might need to create triggers to make your view fully updatable.
For controlling input, you can use a function. (CREATE FUNCTION...) You can write functions in PL/pgSQL. Again, consider revoking permissions on the table.